package com.cserver.pro.service.impl;

import com.cserver.pro.dao.CoursetabDao;
import com.cserver.pro.entity.Coursetab;
import com.cserver.pro.service.CoursetabService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 课程表
(Coursetab)表服务实现类
 *
 * @author makejava
 * @since 2020-02-29 21:38:27
 */
@Service("coursetabService")
public class CoursetabServiceImpl implements CoursetabService {
    @Autowired
    private CoursetabDao coursetabDao;

    /**
     * 通过ID查询单条数据
     *
     * @param courseId 主键
     * @return 实例对象
     */
    @Override
    public Coursetab queryById(Integer courseId) {

        return this.coursetabDao.queryById(courseId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Coursetab> queryAllByLimit(int offset, int limit) {
        return this.coursetabDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param coursetab 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public Coursetab insert(Coursetab coursetab) {
        this.coursetabDao.insert(coursetab);
        return coursetab;
    }

    /**
     * 修改数据
     *
     * @param coursetab 实例对象
     * @return 实例对象
     */
    @Override
    public Coursetab update(Coursetab coursetab) {
        this.coursetabDao.update(coursetab);
        return this.queryById(coursetab.getCourseId());
    }

    /**
     * 通过主键删除数据
     *
     * @param courseId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer courseId) {
        return this.coursetabDao.deleteById(courseId) > 0;
    }
}